![]() |
The development of NesC module in PAT aims at automatically analyzing,
simulating and verifying NesC programs running on TinyOS. Therefore, we tried to
support the full set of NesC syntax, including NesC structures, C-like language
syntax, etc. A NesC application can be implemented by a number of .nc files and
.h files, where .nc files define interface, module, or configuration, and .h
files define some constants and data structures. NesC code implemented in
the form of .nc files and .h files can be compiled, analyzed, simulated and
verified in our tool.
Syntax of an interface definition
file interface name {
(A) NesC
Concepts
Interface
An
nesC interface is defined as the following:
command datatype name(datatype arg1,
...);
...
event datatype name(datatype arg1,
...);
...
}
For example, the content of file Leds.nc defines the interface Leds:
Sample Code: Leds.nc |
interface Leds
{ |
Module
A
nesC module defines a lower-level component, which can be referred by a
higher-level one defined by a configuration. The syntax of a module is given as
the following:
Syntax of a module definition file |
module name
{ |
Sample Code: LedsP.nc |
module LedsP()
{ |
Configuration
A
configuration is the other kind of component (one kind is module) in NesC. A
configuration wires components to one another via bi-directional
interfaces. In a configuration, components are wired to one another via
bi-directional interfaces. These wiring statements are most important, because
they bring all components defined elsewhere together to be an application. Each
NesC application should have a configuration which is the top-level
component and specifies the starting point of its execution.
The syntax of a
configuration is shown below:
Syntax of a configuration definition file |
configuration name
{ |
(B) Datatypes and Data
Structures
NesC supports the whole set of data types and structures of
C language. In PAT, all these types and structures are supported, except
floating and double data.
Category |
Types |
Primary data type |
int, char, void |
Integer type |
int, int8_t, int16_t, int 32_t,
int64_t, |
User defined type |
typedef type identifier |
Enumerated type |
enum identifier {value 1, value 2, ...} |
Structure |
struct |
Pointer |
pointers of the supported types in |
(C) Operators
The NesC module in PAT supports all the operators of NesC, which
are the same as those of C language. The following table shows all the operators
with their precedences, description and associativity.
Precedence | Operator | Description | Associativity |
1 |
++ -- |
Suffix increment and decrement |
Left to right |
2 |
++ -- |
Prefixe increment and decrement |
Right to left |
3 |
* / % |
Multiplication, division, and modulus (remainder) |
Left to right |
4 |
+ - |
Addition and subtraction |
Left to right |
5 |
<< >> |
Bitwise left shift and right shift |
Left to right |
6 |
< <= |
For relational operators less than (LT) and less than or
equal to (LE) |
Left to right |
7 |
== != |
For relational equal to and inequal to |
Left to right |
8 |
& |
Bitwise AND |
Left to right |
9 |
^ |
Bitwise XOR |
Left to right |
10 |
| |
Bitwise OR |
Left to right |
11 |
&& |
Logical AND |
Left to right |
12 |
| | |
Logical OR |
Left to right |
13 |
c ? t : f |
Ternary conditional |
Right to left |
14 |
= |
Direct assignment |
Right to left |
(D) Statements
Some important
statements are given in the following table:
Statement |
Syntax |
if/if-else |
same as C |
while/do-while |
same as C |
for |
same as C |
command call |
call intf.cmd(...); |
event signal |
signal intf.evnt(...); |
task post |
post taskname(); |